package com.iknow.maps;

import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import com.baidu.mapapi.ItemizedOverlay;
import com.baidu.mapapi.MapController;
import com.baidu.mapapi.MapView;
import com.baidu.mapapi.MapView.LayoutParams;
import com.baidu.mapapi.Overlay;
import com.baidu.mapapi.OverlayItem;
import java.util.Iterator;
import java.util.List;

public abstract class BalloonItemizedOverlay<Item extends OverlayItem> extends ItemizedOverlay<Item>
{
  private BalloonOverlayView<Item> balloonView;
  private View.OnClickListener btnClickListener;
  private View clickRegion;
  private int currentFocussedIndex;
  private Item currentFocussedItem;
  private MapView mapView;
  final MapController mc;
  private int viewOffset;

  public BalloonItemizedOverlay(Drawable paramDrawable, MapView paramMapView)
  {
    super(paramDrawable);
    this.btnClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
      }
    };
    this.mapView = paramMapView;
    this.viewOffset = 0;
    this.mc = paramMapView.getController();
  }

  private boolean createAndDisplayBalloonOverlay()
  {
    int i;
    MapView.LayoutParams localLayoutParams;
    if (this.balloonView == null)
    {
      this.balloonView = createBalloonOverlayView();
      this.clickRegion = this.balloonView.findViewById(2131296272);
      this.clickRegion.setOnTouchListener(createBalloonTouchListener());
      i = 0;
      this.balloonView.setVisibility(8);
      List localList = this.mapView.getOverlays();
      if (localList.size() > 1)
        hideOtherBalloons(localList);
      if (this.currentFocussedItem != null)
        this.balloonView.setData(this.currentFocussedItem);
      localLayoutParams = new MapView.LayoutParams(-2, -2, this.currentFocussedItem.getPoint(), 81);
      localLayoutParams.mode = 0;
      this.balloonView.setVisibility(0);
      if (i == 0)
        break label144;
      this.balloonView.setLayoutParams(localLayoutParams);
    }
    while (true)
    {
      while (true)
      {
        return i;
        i = 1;
      }
      label144: this.mapView.addView(this.balloonView, localLayoutParams);
    }
  }

  private View.OnTouchListener createBalloonTouchListener()
  {
    return new View.OnTouchListener(this)
    {
      public boolean onTouch(, MotionEvent paramMotionEvent)
      {
        int i;
        Drawable localDrawable = ((View)paramView.getParent()).findViewById(2131296271).getBackground();
        if (paramMotionEvent.getAction() == 0)
        {
          int[] arrayOfInt = new int[1];
          arrayOfInt[0] = 16842919;
          if (localDrawable.setState(arrayOfInt))
            localDrawable.invalidateSelf();
          i = 1;
        }
        while (true)
        {
          while (true)
          {
            return i;
            if (paramMotionEvent.getAction() != 1)
              break;
            if (localDrawable.setState(new int[0]))
              localDrawable.invalidateSelf();
            this.this$0.onBalloonTap(BalloonItemizedOverlay.access$0(this.this$0), BalloonItemizedOverlay.access$1(this.this$0));
            i = 1;
          }
          i = 0;
        }
      }
    };
  }

  private void hideOtherBalloons(List<Overlay> paramList)
  {
    Iterator localIterator = paramList.iterator();
    while (true)
    {
      Overlay localOverlay;
      do
      {
        if (!(localIterator.hasNext()))
          return;
        localOverlay = (Overlay)localIterator.next();
      }
      while ((!(localOverlay instanceof BalloonItemizedOverlay)) || (localOverlay == this));
      ((BalloonItemizedOverlay)localOverlay).hideBalloon();
    }
  }

  protected BalloonOverlayView<Item> createBalloonOverlayView()
  {
    return new BalloonOverlayView(getMapView().getContext(), getBalloonBottomOffset(), this.btnClickListener);
  }

  public int getBalloonBottomOffset()
  {
    return this.viewOffset;
  }

  public Item getFocus()
  {
    return this.currentFocussedItem;
  }

  protected MapView getMapView()
  {
    return this.mapView;
  }

  protected void hideBalloon()
  {
    if (this.balloonView != null)
      this.balloonView.setVisibility(8);
  }

  protected boolean onBalloonTap(int paramInt, Item paramItem)
  {
    return false;
  }

  protected final boolean onTap(int paramInt)
  {
    this.currentFocussedIndex = paramInt;
    this.currentFocussedItem = createItem(paramInt);
    createAndDisplayBalloonOverlay();
    this.mc.animateTo(this.currentFocussedItem.getPoint());
    return true;
  }

  public void setBalloonBottomOffset(int paramInt)
  {
    this.viewOffset = paramInt;
  }

  public void setFocus(Item paramItem)
  {
    this.currentFocussedItem = paramItem;
    if (this.currentFocussedItem == null)
      hideBalloon();
    while (true)
    {
      return;
      createAndDisplayBalloonOverlay();
    }
  }
}